package me.caofeng.pojo;

import com.fasterxml.jackson.annotation.JsonInclude;
import me.caofeng.enums.OrderStatus;
import me.caofeng.util.DateUtil;
import me.caofeng.util.PriceUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Date;
import java.util.Map;

/**
 * Copyright © 2017曹峰. All rights reserved.
 *
 * @Prject: mall
 * @Package: me.caofeng.pojo
 * @Description: 支付记录
 * @Author: 曹峰 blog.caofeng.me
 * @Date: 2017-06-29 12:20
 * @Version: V1.0
 */

@JsonInclude(JsonInclude.Include.NON_NULL)
public class AlipayInfo extends Pojo {
    private static Logger LOGGER = LogManager.getLogger(AlipayInfo.class);
    /**
     * 用户id
     */
    private String userId;

    /**
     * 通知发送的时间，原始string格式为yyyy-MM-dd HH:mm:ss
     * notify_time
     */
    private Date notifyTime;

    /**
     * 支付宝交易号
     * trade_no
     */
    private String tradeNumber;

    /**
     * 商城订单号
     * out_trade_no
     */
    private String orderId;

    /**
     * 商户业务号,支付宝支付退款申请流水号
     * out_biz_no
     */
    private String outBizNumber;

    /**
     * 买家账号，平台对应
     * buyer_id
     */
    private String buyerId;

    /**
     * 买家支付宝账号
     * buyer_logon_id
     */
    private String buyerName;

    /**
     * 交易状态,需要将支付宝的状态和本系统的状态进行转换
     * trade_status
     */
    private OrderStatus orderStatus;

    /**
     * 订单总金额
     * total_amount
     */
    private int totalAmount;

    /**
     * 实际收到的金额
     * receipt_amount
     */
    private int receiptAmount;

    /**
     * 买家实付金额
     * buyer_pay_amount
     */
    private int payAmount;

    /**
     * 总退款金额
     * refund_fee
     */
    private int refundFee;

    /**
     * 实际退款金额
     * send_back_fee
     */
    private int sendBackFee;

    /**
     * 付款时间 原始string格式为yyyy-MM-dd HH:mm:ss
     * gmt_payment
     */
    private Date payTime;

    /**
     * 退款时间
     * gmt_refund
     */
    private Date refundTime;

    /**
     * 交易结束时间
     */
    private Date closeTime;


    public AlipayInfo() {
    }

   public AlipayInfo(Map<String, String> map) {
        setNotifyTime(DateUtil.stringToDate(map.get("notify_time")));
        setTradeNumber(map.get("trade_no"));
        setOrderId(map.get("out_trade_no"));
        setOutBizNumber(map.get("out_biz_no"));
        setBuyerId(map.get("buyer_id"));
        setBuyerName(map.get("buyer_logon_id"));
        setOrderStatus(OrderStatus.getStatus(map.get("trade_status")));
        setTotalAmount(PriceUtil.stringToInt(map.get("total_amount")));
        setReceiptAmount(PriceUtil.stringToInt(map.get("receipt_amount")));
        setPayAmount(PriceUtil.stringToInt(map.get("buyer_pay_amount")));
        setRefundFee(PriceUtil.stringToInt(map.get("refund_fee")));
        setSendBackFee(PriceUtil.stringToInt(map.get("send_back_fee")));
        setCreateTime(DateUtil.stringToDate(map.get("gmt_create")));
        setPayTime(DateUtil.stringToDate(map.get("gmt_payment")));
        setRefundTime(DateUtil.stringToDate(map.get("gmt_refund")));
        setCloseTime(DateUtil.stringToDate(map.get("gmt_close")));
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Date getNotifyTime() {
        return notifyTime;
    }

    public void setNotifyTime(Date notifyTime) {
        this.notifyTime = notifyTime;
    }

    public String getTradeNumber() {
        return tradeNumber;
    }

    public void setTradeNumber(String tradeNumber) {
        this.tradeNumber = tradeNumber;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getOutBizNumber() {
        return outBizNumber;
    }

    public void setOutBizNumber(String outBizNumber) {
        this.outBizNumber = outBizNumber;
    }

    public String getBuyerId() {
        return buyerId;
    }

    public void setBuyerId(String buyerId) {
        this.buyerId = buyerId;
    }

    public String getBuyerName() {
        return buyerName;
    }

    public void setBuyerName(String buyerName) {
        this.buyerName = buyerName;
    }

    public OrderStatus getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(OrderStatus orderStatus) {
        this.orderStatus = orderStatus;
    }

    public int getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(int totalAmount) {
        this.totalAmount = totalAmount;
    }

    public int getReceiptAmount() {
        return receiptAmount;
    }

    public void setReceiptAmount(int receiptAmount) {
        this.receiptAmount = receiptAmount;
    }

    public int getPayAmount() {
        return payAmount;
    }

    public void setPayAmount(int payAmount) {
        this.payAmount = payAmount;
    }

    public int getRefundFee() {
        return refundFee;
    }

    public void setRefundFee(int refundFee) {
        this.refundFee = refundFee;
    }

    public int getSendBackFee() {
        return sendBackFee;
    }

    public void setSendBackFee(int sendBackFee) {
        this.sendBackFee = sendBackFee;
    }

    public Date getPayTime() {
        return payTime;
    }

    public void setPayTime(Date payTime) {
        this.payTime = payTime;
    }

    public Date getRefundTime() {
        return refundTime;
    }

    public void setRefundTime(Date refundTime) {
        this.refundTime = refundTime;
    }

    public Date getCloseTime() {
        return closeTime;
    }

    public void setCloseTime(Date closeTime) {
        this.closeTime = closeTime;
    }
}
